﻿<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>ManageSystem后台管理系统</title>
    <!-- bootstrap 3.0.2 -->
    <link href="/resource/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <!-- Theme style -->
    <link href="/resource/css/style.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="/resource/js/jQueryMessage/css/message.skin.css" />
</head>

<body>
	<div class="row">
	    <div class="col-md-12">
	    	<h1 class="panel-heading">新增用户</h1>
	        <!--breadcrumbs start -->
	        <ul class="breadcrumb">
				<li><a href="/index/toIndex"><i class="fa fa-home"></i> 首页</a></li>
				<li class="active">新增用户</li>
			</ul>
	        <!--breadcrumbs end -->
	    </div>
	</div>
	<div class="row">
		<div class="col-lg-12">
			<section class="panel">
				<div class="panel-body">
					<form class="col s12" id="form1" enctype="multipart/form-data" th:action="@{/admin/user/add}" onsubmit="return validateForm();" method="post">
						<div class="form-group form-control-medium">
							<label for="realname">真实名称：</label>
							<input id="realname" name="realname" type="text"  class="form-control"/>
						</div>
						<div class="form-group form-control-medium">
							<label for="username">用户昵称：</label>
							<input id="username" name="username" type="text" class="form-control"/>
						</div>
						<div class="form-group form-control-medium">
							<label for="mobile">手机号：</label>
							<input id="mobile" name="mobile" type="text" class="form-control"/>
						</div>
						<div class="form-group form-control-medium">
							<label for="password">密码：</label>
							<input id="password" name="password" type="password" class="form-control"/>
						</div>
						<label for="status">状态：</label>
						<select class="form-group" id="status" name="status">
							<option value="1" selected>启用</option>
							<option value="0">禁用</option>
						</select>
						<label for="newAddTargetDim">角色：</label>
						<select class="form-group" id="newAddTargetDim" name="roleType">
							<!--<option value="1" selected>教师</option>-->
							<!--<option value="2">学生</option>-->
							<option value="3" selected>系统管理员</option>
						</select>
						<input id="createBy" name="createBy" type="hidden" class="form-control" />

						<div class="form-btn-group-left">
			            	<button type="submit" class="btn btn-info">保存</button>
							<button type="button" class="btn btn-info" id="back"><a href="/admin/user/list">返回</a></button>
			            </div>
					</form>
				</div>
			</section>
		</div>
	</div>
	<script src="/resource/js/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="/resource/js/jQueryMessage/js/jquery.plugin.message.js"></script>
    
    <script type="text/javascript" th:inline="javascript">
	   	/* 保存方法 */
	    function validateForm(){
	    	var realname = $("#realname").val();
	    	var username = $("#username").val();
	    	var mobile = $("#mobile").val();
	    	var password = $("#password").val();
			var status = $('select[name="status"]').val();
			var roleType = $('select[name="roleType"]').val();
			console.log(status,roleType)
	    	if(realname == null || realname==''){
	    		$("body").MessageBox({
					type: 'error',
					message:'真实名称不能为空！',
					timeout:3000,
					callbak:null
				});
	    		return false;
	    	}
			if(username == null || username==''){
				$("body").MessageBox({
					type: 'error',
					message:'用户昵称不能为空！',
					timeout:3000,
					callbak:null
				});
				return false;
			}
			if(mobile == null || mobile==''){
				$("body").MessageBox({
					type: 'error',
					message:'手机号不能为空！',
					timeout:3000,
					callbak:null
				});
				return false;
			}
			if(status == null || status==''){
				$("body").MessageBox({
					type: 'error',
					message:'状态不能为空！',
					timeout:3000,
					callbak:null
				});
				return false;
			}
			if(password == null || password==''){
				$("body").MessageBox({
					type: 'error',
					message:'密码不能为空！',
					timeout:3000,
					callbak:null
				});
				return false;
			}
	    	return true;
	    }

		//获取当前登录的用户
		var userStr = sessionStorage.getItem("douglas");
		if(userStr == null || userStr == "" || userStr == "undefined"){
			window.location.href = "/admin/user/toLogin";
		}else{
			var user = JSON.parse(userStr);
			$("#createBy").val(user.realname);
		}
    </script>
</body>
</html>
